﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using M2B.GestionEntretiens.Contracts;
using M2B.GestionEntretiens.POCOS;

namespace M2B.GestionEntretiens.Models
{
    public class QuestionsModel
    {
        #region Properties
        /// <summary>
        /// Questions Service
        /// </summary>
        private IQuestionsService _questionsService;
        /// <summary>
        /// La liste des Questions
        /// </summary>
        public IEnumerable<Question> Questions 
        {
            get
            {
                if (_questionsService == null) return null;
                var questions = _questionsService.GetQuestions();
                return questions;
            }
        }
        #endregion

        #region Constructeurs

        public QuestionsModel(IQuestionsService questionsService)
        {
            _questionsService = questionsService;
           
        }
        #endregion

        #region Méthodes
        /// <summary>
        /// Mise à jour d'une question
        /// </summary>
        /// <param name="question">Question</param>
        public void Update(Question question)
        {
            _questionsService.Update(question);
        }
        /// <summary>
        /// Question à éditer 
        /// </summary>
        /// <param name="questionId">Id</param>
        /// <returns>Question</returns>
        public Question GetQuestion(int questionId)
        {
            return Questions.FirstOrDefault(el => el.QuestionId == questionId);
        }
        /// <summary>
        /// Supprimer une question
        /// </summary>
        /// <param name="questionId">Id</param>
        public void DeleteQuestion(int questionId)
        {
            _questionsService.DeleteQuestion(questionId);
        }
        /// <summary>
        /// Ajouter une question
        /// </summary>
        /// <param name="question">Question</param>
        public void CreateQuestion(Question question)
        {
            _questionsService.AddQuestion(question);
        }
        #endregion


        
    }
}